package com.animation_study.mpandroidchart.fragment;

import com.animation_study.R;
import com.github.mikephil.charting.charts.LineChart;
import com.github.mikephil.charting.components.XAxis;
import com.github.mikephil.charting.data.Entry;
import com.github.mikephil.charting.data.LineData;
import com.github.mikephil.charting.data.LineDataSet;

import java.util.ArrayList;

/**
 * Created by css on 2017/12/25.
 */

public class LineFragment extends BaseFragment {
    private LineChart lineChart;
    private ArrayList<String> lable;
    private ArrayList<Entry> entries;

    @Override
    public int getLayout() {
        return R.layout.fragment_line;
    }

    @Override
    protected void initView() {
        lable = new ArrayList<>();
        entries = new ArrayList<>();
        lineChart = rootView.findViewById(R.id.linechart);
        for (int i = 1; i <= 12; i++) {
            lable.add(i + "次");
            entries.add(new Entry((float) (Math.random() * 100), i));
        }

        LineDataSet lds = new LineDataSet(entries, "折线图学习");
        LineData ld = new LineData(lable, lds);
        lineChart.setData(ld);
        XAxis xAxis = lineChart.getXAxis();

        xAxis.setPosition(XAxis.XAxisPosition.BOTTOM);
        lds.setDrawCubic(true);
    }
}
